<?php

namespace app\controller;

use app\BaseController;
use think\facade\View;
use app\model\WebLink;
use app\Request;
use think\facade\Db;

class Index extends BaseController
{
  public function index()
  {
    return view('index');
  }

  public function first_floor($type=0){
    return view('first_floor');
  }

  public function first_floor_data(Request $request)
  {
    $data = $request->param(); 
    $page = intval(request()->param('page', 1));  // 默认为第1页
    $limit = intval(request()->param('limit', 10));  // 默认每页10条记录
    
    try {
      $query = WebLink::query(); 
      $retData =  $this->getPaginatedData($query, $page, $limit); 
      
      // 返回分页数据
      return json([
        'code' => 0,
        'msg' => 'ok',
        'page' => $page,
        'limit' => $limit,
        'count' => $retData['count'],
        'data' => $retData['data']
      ]);
      
    } catch (\Exception $e) { 
      return response('Error fetching data: ' . $e->getMessage());
    }
  }

  public function second_floor()
  {
    return view();
  }

  public function echart_info()
  {
    return view();
  }

  public function hello($name = 'ThinkPHP8')
  {
    return 'hello,' . $name;
  }
}
